home *** CD-ROM | disk | FTP | other *** search
- Path: inforamp.net!ts10-07
- From: rmorin@inforamp.net (Randy Charles Morin)
- Newsgroups: comp.lang.c++
- Subject: Re: Coding Standards
- Date: Sat, 09 Mar 96 17:40:43 GMT
- Organization: MiddleWorld SoftWare
- Message-ID: <4hsfrc$pmm@sam.inforamp.net>
- References: <4hj8ek$elu@sam.inforamp.net> <4hktar$5o2@galaxy.ucr.edu>
- NNTP-Posting-Host: ts10-07.tor.inforamp.net
- X-Newsreader: News Xpress Version 1.0 Beta #4
-
- In article <4hktar$5o2@galaxy.ucr.edu>, thp@cs.ucr.edu (Tom Payne) wrote:
- >By and large these are good guidelines, and I'd appreciate a copy of them.
- >Some, however, require some exceptions, e.g.:
-
- Ya, common guys. Source files should end with .cc and headers with .hh?
- That's contrary to any standard in existence. A set of coding standards
- should be straight forward, easy to follow and should not contradict normal
- programming practices. The standards I described were exhaustive,
- contradictory to normal programming practices and have already been excused by
- the contractee.
-
- I'll attach a real coding standard, so that you guys who've never seen real
- standards before can be amazed by them. I can't send you a copy of the
- company's coding standard, since that would be in violation of my contract.
- This reasonable standard was developped at another company that I did work
- for. I'm under no obligation not to publish it. Some of the standards apply
- only because of the working environment at the company and shouldn't be taken
- literally in the real world. That is, if you don't have a development server,
- that's OK, most companies don't.
-
- Agrivar
-
- ---------------------------------------------------------------------
-
- Coding Standards
-
- 1 General
-
- 1. All source code must be located in the development directories on the
- development Server.
-
- 2. All C and C++ header files (include files) must have the ".h"
- extension (all class definitions must have the ".hpp" or ô.hö extension), all
- C source files must have the ".c" extension and all C++ source files must have
- the ".cpp" extension.
-
- 3. We must use object oriented programming where possible. Where it is
- not possible to use object oriented programming, we must use functional
- programming. If it is not possible to use object oriented programming or
- functional programming, we will abandon the functionality we are attempting to
- add.
-
- 4. Command line make procedures must be located solely in make files.
- This means no batch file commands that execute the compiler, linker, librarian
- or maker.
-
- 5. Warnings and errors messages must not be suppressed when compiling or
- linking and all warnings and errors must be removed before completion.
-
- 6. We must not use the standard function assert(BOOL) unless it is
- thoroughly documented and the production version is made without any assert
- commands. The assert function is a debugging tool not a production version
- function.
-
- 7. Do not return pointers to data space that was local to the function
- that is returning the pointer. If you must return a pointer to data space,
- then pass the data space as a parameter to the function that will be returning
- the pointer.
-
- 8. If you modify a standard header file or rebuild a standard object
- file, put the modified header, source and object files in the same directory
- structure as our header, source and object files. This way other projects
- will not include this modification and future programmers will know that the
- standard file was modified.
-
- 9. If you receive a pointer as a parameter where the data pointed to by
- the pointer will not be modified, then the parameter declaration should
- include the const modifier.
-
- 10. All header, source, make and resource files should be located in a
- base directory.
-
- 11. C++ inline definitions should be discouraged. Reason: A class
- accessor method is used so that if the data member's format is changed the
- accessor method can be changed such that it continues to return the same
- format. Therefor, if the accessor method is inline and the data member's
- format is changed, then all objects that call the accessor would need
- recompilation rather than only the object that contains the method.
-
- 12. All C++ classes must be checked into the class library.
-
- 13. Data members of classes should be private where possible and accessors
- should be used to give access to users.
-
-
- 2 File Formats
-
- 2.1 Header Files
-
- 1. All header files should begin with the two lines and end with the one
- line outlined below. Do not use the define macro.
-
- #ifndef PROJECTCODE_FILENAME_H
- #define PROJECTCODE_FILENAME_H
- .
- .
- .
- #endif
-
- 2. If a header file requires that a second header file be included in the
- source listing that includes the first header file, then the first header file
- must include the second header file. In other words, you should be able to
- compile your headers.
-
- 3. A header file may include only one object. The implementation of the
- object may be distributed over several source files, but two objects must not
- be implemented in one source file.
-
- 4. The header file must contain a comment header. The comment header
- will have the following format. In the example the header filename is
- "example.h".
-
- /*
- implementation: example.c
- */
-
- 5. A header file should not contain any identifiers, they should contain
- only type definitions. The only exception is C++ class definitions may
- contain inline functions.
-
- 6. If you one need the class name to compile a header, donÆt include the
- classes header, include only the existence of the class. The code below on
- the left is correct and the code below on the right is not.
-
- #ifndef HEADEROFRC1_H
- class c1;
- #endif
- class c2
- {
- void f(c1 * p);
- };
- #include <headerforc1.h>
- class c2
- {
- void f(c1 * p);
- };
-
-
- 2.2 Source Files
-
- 1. Every source file must have an associated header file that defines
- every function, type definition, structure and class. Source files may not
- include any definitions (this includes macro definitions). The source file
- and header file should have the prefix wherever possible.
-
- 2. The source file must contain a comment header. The comment header
- will have the following format. In the example the header filename is
- "example.c".
-
- /*
- definition: example.h
- purpose: To serve as an example
- */
-
- ...During the first modification of a source for version x, the writer
- should delete all modifications for versions previous to x. The result would
- be that all modifications described in the header are for the version in which
- that source was last modified.
-
- 3. Each function will have a comment header. The comment header will
- have the following format. Note the use of the stars to highlight where each
- function begins.
-
- /**********************************
- prototype: example.h (this line is necessary only if it is
- different from the source header, but it does not hurt to include it anyway).
- purpose: To serve as an example
- */
-
- 4. C precompiler macro definitions must be placed in header file when
- possible, although it is understood that this is not always possible.
-
-
- 3 Naming Conventions
-
- 1. All class names should begin with the prefix BELL. Example:
- BELLSuperClass.
-
- 2. Identifiers should contain no underline characters. The first letter
- of every word should be highlighted by capitalizing the letter. Example:
- IndentifierName.
-
- 3. Limited Hungarian notation will be used.
- a Atom
- b BOOL (integer)
- by BYTE (unsigned character)
- c Character (ANSI ASCII 8-bit)
- dw DWORD (unsigned long)
- fn Function
- h HANDLE (unsigned integer)
- hDC HANDLE to a device context
- i Integer
- id Integral id value
- l LONG (long)
- lp Long (far) pointer
- lpsz Long pointer to null-terminated string
- n Short integer
- np Near (short) pointer
- p Pointer
- pfn Function pointer
- pst Pointer to a structure
- psz Pointer to null-terminated string
- pv Pointer to void
- s String
- sz NULL (/0) terminated string
- u Unsigned
- v Void
- w WORD (unsigned integer)
- w Character (Unicode 16-bit)
- x Short (when used as the x coordinate)
- y Short (when used as the y coordinate)
-
- 4. Filename constants must be exactly similar to the actual filename with
- all-caps and an underscore to represent the delimiter between the prefix and
- suffix.
- Example: #define HELLO_H c:\subdir\hello.h
-
-